package cn.tedu.csmall.product.webapi.service;

import cn.tedu.csmall.commons.exception.ServiceException;
import cn.tedu.csmall.commons.response.ServiceCode;
import cn.tedu.csmall.pojo.dto.AttributeAddNewDTO;
import cn.tedu.csmall.pojo.entity.Attribute;
import cn.tedu.csmall.product.sevice.IAttributeService;
import cn.tedu.csmall.product.webapi.mapper.AttributeMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AttributeServiceImpl implements IAttributeService {

    @Autowired
    private AttributeMapper attributeMapper;

    @Override
    public void addNew(AttributeAddNewDTO attributeAddnewDTO) {
        log.debug("增加商品属性：{}", attributeAddnewDTO);
        Attribute attribute = new Attribute();
        BeanUtils.copyProperties(attributeAddnewDTO, attribute);
        int rows = attributeMapper.insert(attribute);
        if (rows != 1) {
            throw new ServiceException(ServiceCode.INTERNAL_SERVER_ERROR, "新增商品属性失败，服务器忙，请稍后再次尝试！");
        }
    }

}
